﻿using EzDesk.Core.Data;
using EzDesk.Core.Model;

namespace EzDesk.Core.ServiceImpl.Services
{
    public static class UserProfileModelEx
    {
        public static SimpleUser ToSimpleUser(this UserProfile userProfile, EzDeskDatabaseContainer container)
        {
            return userProfile.ExtendModel(container).ToSimpleUser();
        }

        public static UserProfile ExtendModel(this UserProfile userProfile, EzDeskDatabaseContainer container)
        {
            if (userProfile != null)
            {
                container.LoadProperty(userProfile, p => p.Dept);
                container.LoadProperty(userProfile, p => p.Position);
                userProfile.HeadUrl = string.Format("/core/headicon/{0}/{1}", userProfile.Id, userProfile.HeadImageId);
            }
            return userProfile;
        }
    }
}